﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;     // DLL support

namespace AV_Monitor
{
    class NmeaParserDllInterface
    {
        private class NativeMethods
        {
            #region PCX03
            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern int SetJoystickX(float value);

            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern int SetJoystickY(float value);

            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern int SetJoystickZ(float value);

            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern int SetThrottle(float value);

            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern int GeneratePCX03([MarshalAs(UnmanagedType.LPArray)] byte[] str);
            #endregion //PCX03

            #region AVX03
            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern float GetYaw();
   
            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern float GetPitch();

            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern float GetRoll();

            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern float GetReserve1();
   
            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern float GetReserve2();
    
            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern float GetReserve3();
    
            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern float GetReserve4();
            #endregion // AVX03

            [DllImport("NmeaParser.dll", CallingConvention = CallingConvention.Cdecl)]
            internal static extern int Parse([MarshalAs(UnmanagedType.LPStr)] string sentence, int buffSize);       
        }
        
        #region PCX03
        public static int SetJoystickXDll(float value)
	    {
            return NativeMethods.SetJoystickX(value);
	    }

        public static int SetJoystickYDll(float value)
	    {
            return NativeMethods.SetJoystickY(value);
	    }

        public static int SetJoystickZDll(float value)
	    {
            return NativeMethods.SetJoystickZ(value);
	    }

        public static int SetThrottleDll(float value)
	    {
            return NativeMethods.SetThrottle(value);
	    }

        public static string GeneratePCX03Dll()
        {
            byte[] str = new byte[256];
            int outSize = NativeMethods.GeneratePCX03(str);
            return System.Text.Encoding.ASCII.GetString(str, 0, outSize);
        }
        #endregion // PCX03

        #region AVX03
        public static float GetYawDll()
        {
            return NativeMethods.GetYaw();
        }

        public static float GetPitchDll()
        {
            return NativeMethods.GetPitch();
        }

        public static float GetRollDll()
        {
            return NativeMethods.GetRoll();
        }

        public static float GetReserve1Dll()
        {
            return NativeMethods.GetReserve1();
        }

        public static float GetReserve2Dll()
        {
            return NativeMethods.GetReserve2();
        }

        public static float GetReserve3Dll()
        {
            return NativeMethods.GetReserve3();
        }

        public static float GetReserve4Dll()
        {
            return NativeMethods.GetReserve4();
        }
        #endregion //AVX03

        #region Parse
        public static int ParseDll(string sentence)
        {
            return NativeMethods.Parse(sentence, sentence.Length);
        }
        #endregion //Parse
    }
}
